
/// MLSDEFORMER source code
/// by Alvaro Cuno, LCG-COPPE-UFRJ 
/// bugs? email-me: alvaroecp@gmail.com
/// January, 2007
   
#ifndef __MESHWITHSKELETON_H__
#define __MESHWITHSKELETON_H__
   
#include "mesh.h"
#include "skeleton.h"
   
//~ namespace MLS {
   
/// This class implements a mesh model attached with 
/// a skeleton structure
class MeshWithSkeleton : public Mesh {
   
public:
   MeshWithSkeleton();
   MeshWithSkeleton(const char* filename);
   ~MeshWithSkeleton();
   
   /// Reads a skeleton for the current model
   void loadSkeleton(const char* filename);
   
   /// Saves the skeleton on file 
   void saveSkeleton(const char* filename);
   
   /// 
   void loadSkinningOnJoints(const char* filename);
   
   /// 
   void loadSkinningOnBones(const char* filename);
   
   /// 
   void saveSkinningOnJoints(const char* filename);
   
   /// 
   void saveSkinningOnBones(const char* filename);
   
   /// Recovers the initial geometry of the skeleted-mesh
   void recoverInitData();
   
   /// transformations
   void rotate(const Point3 &o, const Vector3 &u, Number angle);
   void translate(const Vector3 &t);
   
   /// Reads an off model into a polyhedron data structure and returns it
   /// @param filename Name of the file containing model
   /// @return pointer to newly read model or 0 if unsuccessful
   static MeshWithSkeleton* load_off (const char *filename);
   
   /// Reads a ply model into a polyhedron data structure and returns it
   /// @param filename Name of the file containing model
   /// @return pointer to newly read model or 0 if unsuccessful
   static MeshWithSkeleton* load_ply (const char *filename);
   
   unsigned int nJoints() { return skeleton->nJoints(); }
   unsigned int nBones()  { return skeleton->nBones(); }
   
   /// Computes the Voronoi Area and sin+cos values for all vertices of the mesh
   void computeLaplacianParameters();
   
   void setLapFilterAlpha(float val) { lfalpha = val; }
private:
   
   void computeJointsxVertex();
   void computeBonesxVertex();
   
public:
   Skeleton       *skeleton;            //< the mesh's skeleton
   Skeleton       *i_skeleton;          //< the initial mesh's skeleton: used for reseting the deformation
private:
   Number         difussionSupport;   //< 
   Number         lfalpha; // 
   Number         largest_dvj;   // the largest distance between vertices and joints;
};

//~ } // end MLS namespace
   
#endif
